/*
 * Created on 2008-3-7
 *
 * TODO 
 */
package jacky.lanlan.song.extension.struts.interceptor;

import java.util.List;

import jacky.lanlan.song.extension.struts.InfrastructureKeys;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.upload.FormFile;

/**
 * 清除拦截器，负责清除request里面无用的attribute。优先级400。
 * @author Jacky.Song
 */
@SuppressWarnings("unused")
public class CleanInterceptor extends ActionInterceptorAdapter {

	@SuppressWarnings("unchecked")
	@Override
	public void afterCompletion(HttpServletRequest request, 
			HttpServletResponse response, Object action, Exception ex) throws Exception {
		// 清除在调用执行方法期间添加的临时属性，见POJOActionController.executeBusiness()
		request.removeAttribute(InfrastructureKeys.EXECUTION);
		request.removeAttribute(InfrastructureKeys.VSAC);
		request.removeAttribute(InfrastructureKeys.REQ_DATA);
		
		List<FormFile> uploadFiles=(List<FormFile>) request.getAttribute(InfrastructureKeys.UPLOAD_DATA);
		if(uploadFiles!=null) {
			for (FormFile formFile : uploadFiles) {
				formFile.destroy();
			}
			request.removeAttribute(InfrastructureKeys.UPLOAD_DATA);
		}
	}
	
	public int priority() {
		return 400;//优先级在默认拦截器中最低
	}
	
}
